<template>
  <div id="app">
    <Header></Header>
    <div class="rtview">
      <keep-alive :include="['Home']">
        <router-view></router-view>
      </keep-alive>
    </div>
    <Footer></Footer>
    <GoTop></GoTop>
    <AudioPlayer></AudioPlayer>
    <Login></Login>
  </div>
</template>

<script>
import Header from '@/views/Header/Header.vue'
import Footer from '@/views/Footer/Footer.vue'
import GoTop from '@/components/GoTop.vue'
import AudioPlayer from '@/components/AudioPlayer/AudioPlayer.vue'
import Login from '@/views/Login/Login.vue'
import { loginStatus } from '@/api/login.js'
export default {
  components: { Header, Footer, GoTop, AudioPlayer, Login },
  methods: {
    async getLoginStatus() {
      const { data } = await loginStatus()
      if (data.profile) {
        return true
      } else {
        return false
      }
    }
  },
  created() {
    let cookie = ''
    if (window.localStorage.getItem('cookie')) {
      cookie = window.localStorage.getItem('cookie')
      cookie.split(';;').forEach(item => {
        document.cookie = item
      })
      if (this.getLoginStatus()) {
        this.$store.commit('Login/setisLogin', true)
        this.$store.commit('Login/setUserInfo', JSON.parse(window.localStorage.getItem('userInfo')))
      }
    }
  },
  watch: {
    $route() {
      window.scrollTo(0, 0)
    }
  }
}
</script>

<style lang="less">
@import './style/public.less';
.rtview {
  min-height: 700px;
}
</style>
